

#include <iostream>
#include <vector>
#include <initializer_list>
using namespace std;

class Solution
{
public:
    int removeDuplicates(vector<int>& nums)
    {
        int cur = 0;

        for (int beg = 0; beg < nums.size(); ++beg)
        {
            if (nums[cur] != nums[beg])
            {
                nums[++cur] = nums[beg];
                //std::swap(nums[++cur], nums[beg]);
            }
        }

        return ++cur;
    }

    int MoreThanHalfNum_Solution(vector<int>& numbers)
    {
        int cnt = 0, val = -1;

        for (auto n : numbers)
        {
            if (cnt)
            {
                if (val == n)
                    ++cnt;
                else
                    --cnt;
            }
            else
            {
                val = n;
                ++cnt;
            }
        }

        return val;
    }

    vector<string> letterCombinations(string digits)
    {
        int index = 0;

        if (digits.size())
        {
            ans.reserve(pow(3, digits.size()));
            _backtraking(digits, index, "");
        }

        return ans;
    }

private:
    const vector<string> letters{ "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
    vector<string> ans;

    void _backtraking(const string& digits, int index, string s)
    {
        if (digits.size() == index)
        {
            ans.push_back(s);
            return;
        }

        string str = letters[digits[index] - '0'];
        for (int i = 0; i < str.size(); ++i)
        {
            _backtraking(digits, index + 1, s + str[i]);
        }
    }
};

void Test1()
{
    vector<int> v{ 1, 2, 2, 3, 4, 4, 5 };

    Solution().removeDuplicates(v);

    Solution().letterCombinations("23");

}

void Test2()
{
    vector<int> v{ 1, 2, 3, 4, 5 };

    for (vector<int>::iterator it = v.begin(); it != v.end(); ++it)
    {   
         cout << *it << " ";
    }
    cout << endl;
    

    for (vector<int>::iterator it = v.end(); it != v.begin();)
    {
        --it;

        cout << *it << " ";
    }
    cout << endl;
}

void Test3()
{
    //initializer_list<int> mylist = { 1, 2, 3 };
    auto mylist = { 1, 2, 3 };

    for (auto e : mylist)
    {
        cout << e << " ";
    }
    cout << endl;

    cout << typeid(mylist).name() << endl;
}

void Test4()
{
    int ar[] = { 1,2,3,4,0,5,6,7,8,9 };
    int n = sizeof(ar) / sizeof(int);

    vector<int> v(ar, ar + n);
    vector<int>::iterator it = v.begin();

    while (it != v.end())
    {
        if (*it != 0)
            cout << *it;
        else
            v.erase(it);

        it++;
    }
}

int main()
{
    //Test1();
    //Test2();
    //Test3();
    Test4();

	return 0;
}